package com.hpeng.sys.action;

import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.hpeng.sys.model.SysUser;
import com.hpeng.sys.service.SysUserMgr;
import com.hpeng.util.MD5;
import com.opensymphony.xwork2.ActionSupport;

@Component("updateUserPwdAction")
@Scope("prototype")
public class UpdateUserPwdAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	@Resource
	private SysUserMgr sysUserMgr;
	private String upUserName;
	private String oldPwd;
	private String newPwd;
	private String msg;
    private SysUser sysUser;
	
	public String updateUserPwd() {
		try {
			sysUser = sysUserMgr.getUser(upUserName);
		if(sysUser.getPassword().equals(MD5.toMD5(oldPwd))){
			sysUser.setPassword(MD5.toMD5(newPwd));
			sysUserMgr.updateUser(sysUser);
			msg = getText("密码修改成功！");
		}else{
			msg = getText("输入密码与原始密码不匹配！");
		}
				} catch (Exception e) {
					msg = getText("密码修改失败，请重新输入");
				}
		return "success";
	}
	
	
	/***********************set   get方法***************************/
	public String getUpUserName() {
		return upUserName;
	}

	public void setUpUserName(String upUserName) {
		this.upUserName = upUserName;
	}

	public SysUserMgr getSysUserMgr() {
		return sysUserMgr;
	}

	public void setSysUserMgr(SysUserMgr sysUserMgr) {
		this.sysUserMgr = sysUserMgr;
	}

	public String getOldPwd() {
		return oldPwd;
	}

	public void setOldPwd(String oldPwd) {
		this.oldPwd = oldPwd;
	}

	public String getNewPwd() {
		return newPwd;
	}

	public void setNewPwd(String newPwd) {
		this.newPwd = newPwd;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

}
